// Timelog
import Mock from 'mockjs'
import { formatDate, generateDates } from '../utils'

const getDates = () => {
  // 获取当前日期
  const now = new Date()

  // 设置当前月份的 1 号
  const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1)


  // 返回格式化的日期字符串
  return [
    formatDate(firstDayOfMonth, 'yyyy-MM-dd'), // 当月的 1 号
    formatDate(now, 'yyyy-MM-dd'), // 当天日期
  ]
}
// const today = new Date();
// today.setDate(today.getDate() - 1);
const [firstDay, currentDay] = getDates()
// 计算两个日期之间的毫秒差
const differenceInMilliseconds = (new Date(currentDay)).getTime() - (new Date(firstDay)).getTime();
// 将毫秒差转换为天数并返回
const differenceInDays = differenceInMilliseconds / (1000 * 60 * 60 * 24);
// console.log('differenceInDays', differenceInDays);

const dates = generateDates(firstDay, currentDay);
const percentage = () => {
  let vals = [0, 20, 40, 60, 70, 80, 100]
  const randomNumber = Math.floor(Math.random() * 7); // 生成一个 0 到 7 之间的随机数
  return vals[randomNumber];
}

const time = ['08:00', '09:00', '10:00', '11:00', '11:20', '13:30', '14:00', '15:00', '16:00', '16:50', '17:00', '18:00', '19:00', '20:00']
const timeslot = () => {
  var temp = [];
  for (var i = 0; i < time.length - 1; i++) {
    temp.push({
      id: i,
      start: time[i],
      end: time[i + 1],
      content: Mock.mock('@cparagraph(1, 5)'), // 中文内容  
      project: Mock.Random.pick([1, 2, 3]) // 随机选择1, 2, 3中的一个  
    });
  }
  return temp;
}

const items = []
// 生成10个列表项
for (var i = 0; i <= differenceInDays; i++) {
  items.push({ // 生成10个列表项
    id: Mock.Random.increment(),
    name: Mock.Random.name(),
    date: dates[i],
    percentage: percentage(),
    timeslot: timeslot()
  })
}
// console.log('items', items)
// const list = Mock.mock({
//   'items|16': [{ // 生成10个列表项
//     id: '@increment',
//     name: '@name',
//     date: () => dates.shift()!,
//     percentage,
//     timeslot
//   }]
// })
export default items as any[]

